package be.fw.mana;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Mana extends JFrame implements ActionListener
{
    private static final long serialVersionUID = 7943331369782201176L;
    private JButton butRead = new JButton("Read MANA.DAT to Excel");
    private JButton butWrite = new JButton("Write Excel to MANA_NEW.DAT");

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        new Mana();
    }

    /**
     * Constructor
     */
    public Mana()
    {
        super("BMP MANA.DAT (c) 2011 Frank Wynants");

        try
        {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        }
        catch (ClassNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (InstantiationException e)
        {
            e.printStackTrace();
        }
        catch (IllegalAccessException e)
        {
            e.printStackTrace();
        }
        catch (UnsupportedLookAndFeelException e)
        {
            e.printStackTrace();
        }

        JPanel p = new JPanel(new BorderLayout());
        p.add(new JLabel("<html>This program can be used to edit teamnames and playernames in the 1991 game <br/><b><i>BundesLiga Manager Professional</i></b> also known as <b><i>The Manager</i></b>.<br/><br/>" +
                "Using this program you can export the data from the game to an Excel file, and after editing the Excel file import it into the game.<br/><br/>" +
                "This program must be installed in the main installation folder of the game (alongside MANA.DAT)<br/><br/>" +
        		"Click on 1 of the buttons to use the program.<br/><br/>" +
        		"Please note that during processing the program seems to hang and that this can take a little while.<br/>Just be patient until the completion message appears.</html>"),
                BorderLayout.NORTH);
        JPanel p2 = new JPanel();
        p2.setLayout(new FlowLayout());
        p2.add(butRead);
        p2.add(butWrite);
        p.add(p2, BorderLayout.CENTER);
        this.add(p);
        this.pack();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        butRead.addActionListener(this);
        butWrite.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == butRead)
        {
            new ManaReader();
        }
        else if(e.getSource() == butWrite)
        {
            new ManaWriter();
        }
    }
}